package com.example.ccj.b.c.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.example.ccj.R;

public class ImageAndTextControl extends LinearLayout {
    private String text = "控件";
    private int img_res;

    public ImageAndTextControl(Context context) {
        super(context);
    }

    public ImageAndTextControl(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ImageAndTextControl);
        text = typedArray.getString(R.styleable.ImageAndTextControl_field_name);
        img_res = typedArray.getResourceId(R.styleable.ImageAndTextControl_img_res, R.mipmap.def_select_img);
        typedArray.recycle();
        init(context);
    }

    private void init(Context context){
        LayoutInflater.from(context).inflate(R.layout.custom_control_img_text, this);

        TextView textView = findViewById(R.id.text);
        ImageView img = findViewById(R.id.img);
        textView.setText(text);
        img.setImageResource(img_res);
    }


}
